<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <footer th:fragment="table">
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">公司管理</div>
                            </div>
                            <div class="widget-body  am-fr">

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-4">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success"
                                                        onclick="insert()"><span class="am-icon-plus" data-toggle="modal" data-target="#myModal1"></span> 新增
                                                </button>
                                                <button type="button" class="am-btn am-btn-default am-btn-danger"
                                                        onclick="del()"><span class="am-icon-trash-o"></span> 删除
                                                </button>
                                                <!--<button type="button" class="am-btn am-btn-default am-btn-warning" onclick="insert()"><span class="am-icon-plus"></span> 导入</button>-->
                                                <!--<button type="button" class="am-btn am-btn-default am-btn-secondary" onclick="derives()"><span class="am-icon-trash-o"></span> 导出</button>-->
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}" id="companystatus"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="珠宝行业" th:selected="${companystatus=='珠宝行业'}">房产抵押</option>
                                            <option value="商超行业" th:selected="${companystatus=='商超行业'}">车辆抵押</option>
                                            <option value="食品行业" th:selected="${companystatus=='食品行业'}">信用贷款</option>
                                        </select>
                                        <select data-am-selected="{btnSize: 'sm'}" id="pagesize"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="5" th:selected="${pagesize==5}">5</option>
                                            <option value="10" th:selected="${pagesize==10}">10</option>
                                            <option value="10" th:selected="${pagesize==15}">15</option>
                                            <option value="10" th:selected="${pagesize==20}">20</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field" th:value="${#dates.format(predate,'yyyy-MM-dd')}" id="predate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field " th:value="${#dates.format(nextdate,'yyyy-MM-dd')}" id="nextdate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field " id="companykeyword" th:value="${companykeyword}">
                                        <span class="am-input-group-btn">
                                         <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
                                                 type="button" th:onclick="|page('${companydetails.pageNum}')|"></button>
                                    </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                    <div style="overflow-x:scroll">
                                        <table class="am-table am-table-compact am-table-striped tpl-table-black "
                                               id="example-r" style="width: 2000px">
                                            <thead>
                                            <tr>
                                                <th>
                                                    <button onclick="reSelectcre()"
                                                            class="am-btn  am-btn-default am-btn-success tpl-table-list-field"
                                                            type="button">反选
                                                    </button>
                                                </th>
                                                <th>编号</th>
                                                <th>公司名称</th>
                                                <th>公司创建时间</th>
                                                <th>公司地址</th>
                                                <th>公司所属行业</th>
                                                <th>公司部门管理</th>
                                                <th>公司财务管理</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr class="gradeX" th:each="company,s : ${companydetails.list}">
                                                <td><input type="checkbox" name="persons" th:value="${company.companyId}" class="choice"></td>
                                                <td th:text="${s.index}">编号</td>
                                                <td th:text="${company.companyName}">公司名称</td>
                                                <td th:text="${#dates.format(company.companyTime,'yyyy-MM-dd')}">公司创建时间</td>
                                                <td th:text="${company.companyAddress}">公司地址</td>
                                                <td th:text="${company.companyType}">公司所属行业</td>
                                                <td th:text="${company.companyManagestatus}">公司所属行业</td>
                                                <td th:text="${company.companyMoneystatus}">公司所属行业</td>
                                                <td>
                                                    <div class="tpl-table-black-operation">
                                                        <a href="javascript:;" data-toggle="modal" data-target="#myModal2" th:onclick="|findmost('${company.companyId}')|" >更多信息</a>
                                                        <a href="javascript:;" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash" th:onclick="|delone('${company.companyId}')|"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-u-lg-3">
                                            跳转至:<input type="number" id="num"  class="selectOption">/ 页
                                            <span>
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="findpage()"></button>
                                        </span>
                                        </div>

                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">
                                                <li ><a href="javascript:" th:onclick="|page('${companydetails.navigateFirstPage}')|">首页</a></li>
                                                <li  th:if="companydetails.hasPreviousPage"><a href="javascript:" th:onclick="|page('${companydetails.prePage}')|">«</a></li>


                                                <li th:each="pageNum:${#numbers.sequence(1,companydetails.pages)}">
                                                    <a th:text="${pageNum}" th:onclick="|page('${pageNum}')|"></a>
                                                </li>


                                                <li th:if="companydetails.hasNextPage"><a href="javascript:" th:onclick="|page('${companydetails.nextPage}')|">»</a></li>
                                                <li><a href="javascript:" th:onclick="|page('${companydetails.navigateLastPage}')|">尾页</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true" style="margin-top: 100px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel2">查看充值更多信息</h4>
                        </div>
                        <div style="text-align: center" id="comdetail">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>



            <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 100px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">增加项目</h4>
                        </div>
                        <div id="model">
                            <form>
                                公司名称:<input type="text" id="companyName"><br />
                                公司注册时间:<input type="date" id="companyTime"><br/>
                                公司地址:<input type="text" id="companyAddress"><br/>
                                公司行业类别:<input type="text" id="companyType"><br/>
                                公司管理:<input type="text" id="companyManagestatus"><br/>
                                公司财务管理:<input type="text" id="companyMoneystatus"><br/>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" th:onclick="subload()">提交</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
            <input type="hidden" id="allid" th:value="${ids}">
        </div>
    </footer>
    <script>

        /*反选*/
        function reSelectcre() {
            var allids=$('#allid').val().split(',')
            var allid=[]
            allid.push(parseInt(allids[0].split('')[1]))
            for(var i=1;i<allids.length;i++){
                allid.push(parseInt(allids[i]))
            }
            for(var i=0;i<ids.length;i++){
                for (var j=0;j<allid.length;j++){
                    if(allid[j]==ids[i]){
                        allid.splice(j,1)
                    }
                }
            }
            ids=allid
            $("input[name='persons']").each(function () {
                $(this).prop("checked",!$(this).prop("checked"))
            })
        }

        function page(i) {
            $.ajax({
                url:"/p2p/mycompany/getmycompanydetail",
                data:{
                    "companystatus":$("#companystatus").val(),
                    "predate":$("#predate").val(),
                    "nextdate":$("#nextdate").val(),
                    "companykeyword":$("#companykeyword").val(),
                    "pagenum":i,
                    "pagesize":$("#pagesize").val(),
                },
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }


        function findpage() {
            var pagesnum=$('#num').val();
            page(pagesnum);
        }


        $(".choice").click(function () {
            if($(this).prop("checked")){
                if(!($(this).val() in ids)){
                    ids.push($(this).val())
                }
            }else if(!$(this).prop("checked")){
                for (var i=0;i<ids.length;i++){
                    if(ids[i]===$(this).val()){
                        ids.splice(i,1);
                    }
                }
            }
        })





        function findmost(i) {
            $.ajax({
                url: "/p2p/mycompany/getcompanydetail",
                data:{"id":i},
                type: "get",
                dataType:"json",
                success:function (data) {
                    console.log(data)
                    var s="";
                    s+="<div class=\"modal-body\">\n" +
                    for (let j = 0; j <data.length ; j++) {
                        var min=data[j]
                        s+="分公司名称<div>"+min.mincompanyName+"</div>\n" +
                           "注册资金<div>"+min.mincompanyMoney+"</div>\n"
                    }
                    s+="\n" +
                    "</div>"
                    $('#comdetail').html(s)
                },
            })
        }



        //增加
        function subload() {
            $.ajax({
                url:"/p2p/mycompany/insertCompany",
                data:{
                    "companyName":$("#companyName").val(),
                    "companyTime":$("#companyTime").val(),
                    "companyAddress":$("#companyAddress").val(),
                    "companyType":$("#companyType").val(),
                    "companyManagestatus":$("#companyManagestatus").val(),
                    "companyMoneystatus":$("#companyMoneystatus").val(),
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜添加成功!");
                        page(1);
                    }else{
                        alert("抱歉,添加失败!");
                    }
                }
            })
        }

        //删除单个
        function delone(i) {
            $.ajax({
                url:"/p2p/mycompany/delonecompany",
                data:{
                    "id":i,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功")
                        page(1);
                    }else{
                        alert("清先删除项目,再进行删除,删除失败!")
                    }
                }
            })
        }



        //批量删除
        function del() {
            var ides=ids;
            $.ajax({
                url:"/p2p/mycompany/delallcompany",
                data:{
                    "id":ides,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功");
                        page(1);
                        ids=[];
                    }else {
                        alert("清先删除项目,再删除项目公司还款信息,谢谢!");
                    }
                }
            })
        }



        function derives() {
            alert("1111")
            var ides=ids;
            location.href="/p2p/mycompany/companyderive?id="+ides;
            ids=[];
        }







    </script>
</head>
</html>
